package edu.hawaii.halealohacli.command;

import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;
import org.wattdepot.util.tstamp.Tstamp;

/**
 * Tests that CurrentPower is >= 0 and does not throw an exception.
 * 
 * @author David Wilkie
 * @author Branden Ogata
 */
public class TestCurrentPower {

  /**
   * Tests CurrentPower.
   * @throws Exception if there's an error with the server.
   */
  @Test public void test() throws Exception {
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    Source testSource = client.getSources().get(0);
    CurrentPower test = new CurrentPower();
    XMLGregorianCalendar testTimestamp = Tstamp.makeTimestamp();

    // A manual test
    test.printResults(client, testSource, testTimestamp);

    // Tests validity of output
    Double energyConsumed = test.getPowerConsumed();
    assertTrue("Energy consumed is less than zero.", energyConsumed >= 0);
  }
}
